#include "playMessage.h"
#include <rapidjson/document.h>
#include "jsonUtils.h"

PlayMessage::PlayMessage(MtpProtocol* packet) : MtpMessage(packet) , movieId(0),scene(0)
{
}

PlayMessage::PlayMessage(const int64_t& movieId, const int& scene) : MtpMessage(new MtpProtocol(L"play")),movieId(movieId),scene(scene)
{
}

int64_t PlayMessage::getMovieId()
{
	return movieId;
}

int PlayMessage::getScene()
{
	return scene;
}

void PlayMessage::decodeBody()
{
	MtpMessage::decodeBody();
	if (!jsonContent.empty()) {
		JsonDoc doc;
		doc.Parse(jsonContent.c_str());
		JsonUtils::loadLong(doc, L"movieId", movieId);
		JsonUtils::loadInt(doc, L"scene", scene);
	}
}

void PlayMessage::encodeBody()
{
	JsonDoc doc;
	doc.SetObject();
	doc.AddMember(L"movieId", movieId,doc.GetAllocator());
	doc.AddMember(L"scene", scene, doc.GetAllocator());
	jsonContent = JsonUtils::jsonStr(doc);
	MtpMessage::encodeBody();
}
